import Vue from 'vue'
import Router from 'vue-router'
import UcenterRoutes from './ucenter'
Vue.use(Router)

var routes= [
    {
        path: '/',
        redirect: '/index',
    },
    {
        path: '/index',
        component:() => import( /*webpackChunkName: "index" */ '@/components/index/index'),
        meta:{title:'首页'}
    },
    {
        path: '/register',
        component:() => import( /*webpackChunkName: "sign" */ '@/components/sign/register'),
        meta:{title:'注册'}
    },
    {
        path: '/login',
        component:() => import( /*webpackChunkName: "sign" */ '@/components/sign/login'),
        meta:{title:'登录'}
    },
    {
        path: '/user',
        component:() => import( /*webpackChunkName: "user" */ '@/components/ucenter/user'),
        meta:{title:'个人中心'}
    },
    {
        path: '/volunteerSort',
        component:() => import( /*webpackChunkName: "volunteerSort" */ '@/components/volunteerSort/volunteerSort'),
        meta:{title:'志愿排名'}
    },
    {
        path: '/voluteerActivity',
        component:() => import( /*webpackChunkName: "voluteerActivity" */ '@/components/voluteerActivity/voluteerActivity'),
        meta:{title:'志愿服务活动'}
    },
    {
        path: '/voluteerActivityDetail/:id',
        component:() => import( /*webpackChunkName: "voluteerActivityDetail" */ '@/components/voluteerActivity/voluteerActivityDetail'),
        meta:{title:'志愿服务活动'}
    },
    {
        path: '/myOrder',
        component:() => import( /*webpackChunkName: "myOrder" */ '@/components/myOrder/index'),
        meta:{title:'我要点单'}
    },
    {
        path: '/myOrder/category',
        name: 'myOrderCategory',
        component:() => import( /*webpackChunkName: "myOrderDetails" */ '@/components/myOrder/category'),
        meta:{title:'我要点单'}
    },
    {
        path: '/myOrder/list',
        name: 'myOrderList',
        component:() => import( /*webpackChunkName: "myOrderList" */ '@/components/myOrder/list'),
        meta:{title:'我要点单'}
    },
    {
        path: '/myOrder/detail',
        component:() => import( /*webpackChunkName: "myOrderDetail" */ '@/components/myOrder/detail'),
        meta:{title:'我要点单'}
    },
    {
        path: '/myOrder/form',
        component:() => import( /*webpackChunkName: "myOrderForm" */ '@/components/myOrder/form'),
        meta:{title:'我要点单'}
    },
    {
        path: '/star/list',
        component:() => import( '@/components/star/list'),
    },
    {
        path: '/article/detail/:id',
        component:() => import( '@/components/article/detail'),
    },
    {
        path: '/team',
        component:() => import( '@/components/team/list'),
    },
    {
        path: '/team/detail/:id',
        component:() => import( '@/components/team/listDetail'),
    },
    {
        path: '/learning',
        component:() => import( '@/components/learning/list'),
    },

]
routes=[...UcenterRoutes,...routes]
const router = new Router({
    linkExactActiveClass: 'active',
    routes
})

router.afterEach(route => {
    // 从路由的元信息中获取 title 属性
    if (route.meta.title) {
        document.title = route.meta.title
        if (navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)) {
            const hackIframe = document.createElement('iframe')
            hackIframe.style.display = 'none'
            document.body.appendChild(hackIframe)
            setTimeout(() => {
                document.body.removeChild(hackIframe)
            }, 300)
        }
    }
})

const changeBgGroup = ['user']
export default {
    routes,
    router,
    changeBgGroup
}